﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Person.Classes;

namespace Person
{
    public class ListOfPersons:List<Persona>
    {
        public static IPerson ds = null;

        public void Create(Persona p)
        {           
            ds.Create(p);
            this.Add(p);
        }
        public List<Persona> Read()
        {
            this.Clear();
            this.AddRange(ds.Read());
            return this;
        }
        public List<Persona> Read(int ID)
        {
            this.Clear();
            this.AddRange(ds.Read(ID));
            return this;
        }
        public void Update(Persona p)
        {           
            ds.Update(p);
            this.Clear();
            this.AddRange(ds.Read());
        }
        public void Delete(int ID)
        {
            ds.Delete(ID);
            this.Clear();
            this.AddRange(ds.Read());
        }

        public bool Compare(List<Persona> compList)
        {            
            bool res = false;
            if (compList.Count != this.Count) res = false;
            else
            {
                res = true;
                for (int i = 0; i < this.Count; i++)
                {
                        if (this[i].ID != compList[i].ID ||
                            this[i].Fname != compList[i].Fname ||
                            (this[i]).Lname != (compList[i]).Lname ||
                            (this[i]).Age != (compList[i]).Age)
                        {
                            res = false;
                            break;
                        }
                    
                }
            }
            return res;
        }
    }
    
}
